//
//  NSString+DeviceTypeHelper.m
//  golfMaster
//
//  Created by snack on 14-10-13.
//  Copyright (c) 2014年 Master. All rights reserved.
//

#import "NSString+DeviceTypeHelper.h"
#import <sys/utsname.h>


@implementation NSString (DeviceTypeHelper)

+ (instancetype)deviceType
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    // iPhone
    if([deviceModel isEqual:@"i386"])      return @"Simulator";
    if([deviceModel isEqual:@"x86_64"])    return @"Simulator";
    if([deviceModel isEqual:@"iPhone1,1"]) return @"iPhone1G";
    if([deviceModel isEqual:@"iPhone1,2"]) return @"iPhone3G";
    if([deviceModel isEqual:@"iPhone2,1"]) return @"iPhone3GS";
    if([deviceModel isEqual:@"iPhone3,1"]) return @"iPhone4"; // iPhone4 AT&T
    if([deviceModel isEqual:@"iPhone3,2"]) return @"iPhone4";
    if([deviceModel isEqual:@"iPhone3,3"]) return @"iPhone4";
    if([deviceModel isEqual:@"iPhone4,1"]) return @"iPhone4S";
    if([deviceModel isEqual:@"iPhone5,1"]) return @"iPhone5";
    if([deviceModel isEqual:@"iPhone5,1"]) return @"iPhone5";
    if([deviceModel isEqual:@"iPhone5,2"]) return @"iPhone5";
    if([deviceModel isEqual:@"iPhone5,3"]) return @"iPhone5C";
    if([deviceModel isEqual:@"iPhone5,4"]) return @"iPhone5C";
    if([deviceModel isEqual:@"iPhone6,1"]) return @"iPhone5S";
    if([deviceModel isEqual:@"iPhone6,2"]) return @"iPhone5S";
    if([deviceModel isEqual:@"iPhone7,1"]) return @"iPhone6Plus";
    if([deviceModel isEqual:@"iPhone7,2"]) return @"iPhone6";
    
    // iPads
    if([deviceModel isEqual:@"iPad1,1"]) return @"iPad1";
    if([deviceModel isEqual:@"iPad2,1"]) return @"iPad1";
    if([deviceModel isEqual:@"iPad2,2"]) return @"iPad1";
    if([deviceModel isEqual:@"iPad2,3"]) return @"iPad1";
    if([deviceModel isEqual:@"iPad2,4"]) return @"iPad1";
    if([deviceModel isEqual:@"iPad2,5"]) return @"iPadMini";
    if([deviceModel isEqual:@"iPad2,6"]) return @"iPadMini";
    if([deviceModel isEqual:@"iPad2,7"]) return @"iPadMini";
    if([deviceModel isEqual:@"iPad3,1"]) return @"iPad3";
    if([deviceModel isEqual:@"iPad3,2"]) return @"iPad3";
    if([deviceModel isEqual:@"iPad3,3"]) return @"iPad3";
    if([deviceModel isEqual:@"iPad3,4"]) return @"iPad4";
    if([deviceModel isEqual:@"iPad3,5"]) return @"iPad4";
    if([deviceModel isEqual:@"iPad3,6"]) return @"iPad4";
    if([deviceModel isEqual:@"iPad4,1"]) return @"iPadAir";
    if([deviceModel isEqual:@"iPad4,2"]) return @"iPadAir";
    if([deviceModel isEqual:@"iPad4,4"]) return @"iPadMiniRetina";
    if([deviceModel isEqual:@"iPad4,5"]) return @"iPadMiniRetina";
    
    return @"unkonw device";
}

@end
